package com.csy.user.controller;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.user.entity.ParkSpace;
import com.csy.user.service.IParkSpaceService;

/**
 * <p>
 *  车位控制器
 * </p>
 *
 * @author 
 * @since 2025-02-27
 */
@RestController
@RequestMapping("/system/parkSpace")
public class ParkSpaceController extends BaseController {
    @Resource
    private IParkSpaceService parkSpaceService;

    /**
     * 统计车位数量
     * @return
     */
    @GetMapping("/countParkSpace")
    public BaseResponse<Integer> countParkSpace(){
        int parkSpace = parkSpaceService.countParkSpace();
        return BaseResponse.success(parkSpace);
    }

    /**
     * 查询车位列表
     * @param parkSpace
     * @return
     */
    @GetMapping("/list")
    public PageResult list(ParkSpace parkSpace){
        startPage();
        List<ParkSpace> list = parkSpaceService.getSpaces(parkSpace);
        return getData(list);
    }

    /**
     * 查询车位
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public BaseResponse<ParkSpace> getById(@PathVariable("id") Integer id){
        return BaseResponse.success(parkSpaceService.getById(id));
    }

    /**
     * 新增
     * @param parkSpace
     * @return
     */
    @PostMapping
    public BaseResponse<Integer> add(@RequestBody ParkSpace parkSpace){
        boolean b = parkSpaceService.save(parkSpace);
        return toAjax(b == true ? 1 : 0);
    }

    /**
     * 修改
     * @param parkSpace
     * @return
     */
    @PutMapping
    public BaseResponse<Integer> update(@RequestBody ParkSpace parkSpace){
        boolean b = parkSpaceService.updateById(parkSpace);
        return toAjax(b == true ? 1 : 0);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public BaseResponse<Integer> del(@PathVariable("id")Integer id){
        boolean b = parkSpaceService.removeById(id);
        return toAjax(b == true ? 1 : 0);
    }
}
